package com.taotao.portal.service.impl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.taotao.common.pojo.TaotaoResult;
import com.taotao.common.utils.HttpClientUtil;
import com.taotao.pojo.TbItemDesc;
import com.taotao.pojo.TbItemParamItem;
import com.taotao.portal.pojo.ItemInfo;
import com.taotao.portal.service.ItemService;

@Service
public class ItemServiceImpl implements ItemService {
	
	@Value("${REST_BASE_URL}")
	private String REST_BASE_URL;
	
	@Value("${ITEM_INFO_URL}")
	private String ITEM_INFO_URL;
	
	@Value("${ITEM_DESC_URL}")
	private String ITEM_DESC_URL;
	
	@Value("${ITEM_PARAM_URL}")
	private String ITEM_PARAM_URL;
	
	@Override
	public ItemInfo getItemInfoById(Long id) throws Exception {
		String doGet = HttpClientUtil.doGet(REST_BASE_URL+ITEM_INFO_URL+"/"+id);
		TaotaoResult result = TaotaoResult.formatToPojo(doGet, ItemInfo.class);

		if(result.getStatus()==200)
			return (ItemInfo) result.getData();
		throw new Exception(result.getMsg());
	}

	@Override
	public TbItemDesc getItemDescById(Long id) throws Exception {
		String doGet = HttpClientUtil.doGet(REST_BASE_URL+ITEM_DESC_URL+"/"+id);
		TaotaoResult result = TaotaoResult.formatToPojo(doGet, TbItemDesc.class);

		if(result.getStatus()==200)
			return (TbItemDesc) result.getData();
		throw new Exception(result.getMsg());
	}

	@Override
	public TbItemParamItem getItemParamById(Long id) throws Exception {
		String doGet = HttpClientUtil.doGet(REST_BASE_URL+ITEM_PARAM_URL+"/"+id);
		TaotaoResult result = TaotaoResult.formatToPojo(doGet, TbItemParamItem.class);

		if(result.getStatus()==200)
			return (TbItemParamItem) result.getData();
		throw new Exception(result.getMsg());
	}

}
